/*
 * @Author: Anan 
 * @Date: 2022-05-09 22:49:52 
 * @Last Modified by: Anan
 * @Last Modified time: 2022-05-12 14:48:20
 */



import { Effect, Reducer } from 'umi';
import { login } from '@/services'
import Cookies from 'js-cookie'
// import { IProdTag } from '@/types'

export interface UserModelState {
  UserList: [];
}

export interface UserModelType {
  namespace: 'login';
  state: UserModelState;
  effects: {
    getLoginList: Effect;
  };
  reducers: {
    save: Reducer<UserModelState>;
  };
}

const ProdTagModel: UserModelType = {
  namespace: 'login',
  state: {
    UserList: [],
  },

  effects: {
    *getLoginList({ payload }, { call, put }) {
      let result = yield call(login, payload);
      console.log(result);
      
      if (result) {
        Cookies.set('token', result.access_token)
        window.location.href = '/prod-prodList'
        yield put({
          type: 'save',
          payload: {
            userList: result.data
          }
        })
      }
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};

export default ProdTagModel;
